import Vue from 'vue'
import VueRouter from 'vue-router'
import Business from "@/views/business/Business";
import Login from "@/Login";

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect: '/login'
  },
  {
    path:'/login',
    component: Login
  },
  {
    path:'/business',  //业务桌面
    component: Business,
    children:[
      {path:'', redirect:'order'},
      {path:'order', component: () => import("../views/business/order/Order")},
      // {path:'companyService', component: ()=>import("../views/business/product/CompanyService")},
      {path:'qualificationCertificate', component: ()=>import("../views/business/product/QualificationCertificate")},
      {path:'legalInstrument', component: ()=>import("../views/business/product/LegalInstrument")},
      {path:'intellectualProperty', component: ()=>import("../views/business/product/IntellectualProperty")},
      {path:'legalConsult', component: ()=>import("../views/business/product/LegalConsult")},
      // {path:'product', component: ()=>import("../views/business/Product")},
      // {path:'contract', component: ()=>import("../views/business/Contract")},
      // {path:'legalConsultation', component:()=>import("../views/business/LegalConsultation")},
      {path:'user', component: ()=>import("../views/business/user/User")}
    ]
  },
  {
    path: '/portal', //门户管理
    component: () => import('../views/portal/Portal'),
    children: [
      {path:'', redirect: 'article'},
      {path: 'article', component: ()=>import('../views/portal/Article')},
      {path:'evaluation', component:()=>import("../views/portal/Evaluation")}
    ]
  },
  {
    path: '/system',  //系统管理
    component: () => import('../views/system/System'),
    children :[
      {path:'', redirect: 'administrator'},
      {path: 'administrator', component:()=>import("../views/system/administrator/Administrator")},
      {path:'notice', component: ()=>import("../views/system/Notice")}
    ]
  },
  {
    path: '/profile',  //我的信息
    component: () => import('../views/profile/Profile'),
    children: [
      {path:'',redirect: 'baseInfo'},
      {path:'baseInfo', component: ()=>import("../views/profile/BaseInfo")},
      {path:'changeInfo', component: ()=>import("../views/profile/ChangeInfo")},
      {path: 'changePass', component: ()=>import("../views/profile/ChangePass")}
    ]
  }
]

const router = new VueRouter({
  routes,
  mode : 'history',
  base:'/admin/'
})
router.beforeEach((to,from,next)=>{
  if(to.path=='/'||to.path=='/login') {
    return next();
  }else{
    if(!window.localStorage.getItem("admin")){
      return next('/login');
    }
    else{
      next();
    }
  }
})

export default router
